﻿
Partial Class ForgotPassPage
    Inherits System.Web.UI.Page

    Protected Sub wizForgotPass_ActiveStepChanged(sender As Object, e As System.EventArgs) Handles wizForgotPass.ActiveStepChanged

    End Sub

    Protected Sub vldCustUserName_ServerValidate(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles vldCustUserName.ServerValidate
        'Check if UserName is registered
        Dim tmpUser As New User(args.Value)
        If tmpUser.isValid Then
            args.IsValid = True
            'Store user in viewstate for later retrieval
            ViewState("UserObject") = tmpUser
            lblQ1.Text = tmpUser.SecurityQ1
            lblQ2.Text = tmpUser.SecurityQ2
        Else
            args.IsValid = False
        End If
    End Sub

    Protected Sub wizForgotPass_NextButtonClick(sender As Object, e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles wizForgotPass.NextButtonClick
        If Not Page.IsValid Then
            e.Cancel = True
        End If
    End Sub

    Protected Sub wizForgotPass_FinishButtonClick(sender As Object, e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles wizForgotPass.FinishButtonClick
        If Not Page.IsValid Then
            e.Cancel = True
        End If
        If CType(ViewState("UserObject"), User).ChangePassword(txtPassword.Text) Then
            CType(ViewState("UserObject"), User).Login()
            Session("UserObject") = ViewState("UserObject")
            Response.Redirect("MyProfile.aspx")
        Else
            e.Cancel = True
            lblErrorMsg.Text = "An error occurred, please try again."
        End If

    End Sub

    Protected Sub vldCusSecurityA2_ServerValidate(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles vldCusSecurityA2.ServerValidate
        If args.Value.ToLower = CType(ViewState("UserObject"), User).SecurityA2.ToLower Then
            args.IsValid = True
        Else
            args.IsValid = False
        End If
    End Sub

    Protected Sub vldCusSecurityA1_ServerValidate(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles vldCusSecurityA1.ServerValidate
        If args.Value.ToLower = CType(ViewState("UserObject"), User).SecurityA1.ToLower Then
            args.IsValid = True
        Else
            args.IsValid = False
        End If
    End Sub
End Class
